package org.pz.controller;

import org.pz.entity.MallResult;
import org.pz.service.ScheduleService;
import org.pz.validation.BeanScheduleAdd;
import org.pz.validation.BeanScheduleOperate;
import org.pz.validation.BeanScheduleUpdate;
import org.pz.vo.TaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class ScheduleTaskController {

    @Autowired
    private ScheduleService scheduleService;

    @PostMapping("/add")
    public MallResult addSchedule(@RequestBody @Validated(BeanScheduleAdd.class) TaskVo taskVo){
        scheduleService.addCronJob(taskVo);
        return MallResult.success();
    }

    @PostMapping("/update")
    public MallResult updateSchedule(@RequestBody @Validated(BeanScheduleUpdate.class) TaskVo taskVo){
        return scheduleService.updateCronJob(taskVo);
    }

    @PostMapping("/pause")
    public MallResult pauseSchedule(@RequestBody @Validated(BeanScheduleOperate.class) TaskVo taskVo){
        return scheduleService.pauseCronJob(taskVo);
    }

    @PostMapping("resume")
    public MallResult resumeSchedule(@RequestBody @Validated(BeanScheduleOperate.class) TaskVo taskVo){
        return scheduleService.resumeCronJob(taskVo);
    }

    @PostMapping("drop")
    public MallResult dropSchedule(@RequestBody @Validated(BeanScheduleOperate.class) TaskVo taskVo){
        return scheduleService.deleteCronJob(taskVo);
    }

}
